// pages/member/distribution/addbank.js


import { SaveAlipay } from '../../../api/member'
import { list } from '../../../api/point'

const app = getApp()
Page({

    data: {
        // pageNum: 1,
        // pageSize: 20,
        // detailedList: []
        bankInfoId:"2",
        bankName:'321',
        bankNum:'321',
    },

    onLoad: function (options) {
        // this.loadlist()
        // this.getdata()
    },
    addbank(){
        var param = {
            bankInfoId:this.data.bankInfoId,
            bankName:this.data.bankName,
            bankNum:this.data.bankNum
        }
        SaveAlipay(param).then(res=>{
            console.log(res)
        })
        console.log("321321")
    },

    getdata(){
        console.log("123321123")
        if (this.data.pageNum == 1) {
            this.data.detailedList = []
        }
        list({
            pageSize: this.data.pageSize,
            pageNum: this.data.pageNum
        }).then(res => {
            res.data.data.forEach(item => {
                item.createDate = this.formatDate2Time(item.createDate)
                item.thumbnail = 'http://cdn.rzico.com/v4.0/wallet-consumption.png'
                this.data.detailedList.push(item)
            })

            this.setData({
                detailedList: this.data.detailedList
            })
        })
    },
    formatDate2Time(val) {
        let date = new Date(val);
        let y = date.getFullYear();
        let MM = date.getMonth() + 1;
        MM = MM < 10 ? ('0' + MM) : MM;
        let d = date.getDate();
        d = d < 10 ? ('0' + d) : d;
        let h = date.getHours();
        h = h < 10 ? ('0' + h) : h;
        let m = date.getMinutes();
        m = m < 10 ? ('0' + m) : m;
        let s = date.getSeconds();
        s = s < 10 ? ('0' + s) : s;
        return y + '-' + MM + '-' + d + " " + h + ":" + m + ":" + s;
    },

    loadlist() {
        if (this.data.pageNum == 1) {
            this.data.detailedList = []
        }
        list({
            pageSize: this.data.pageSize,
            pageNum: this.data.pageNum
        }).then(res => {
            res.data.data.forEach(item => {
                item.createDate = this.formatDate2Time(item.createDate)
                item.thumbnail = 'http://cdn.rzico.com/v4.0/wallet-consumption.png'
                this.data.detailedList.push(item)
            })

            this.setData({
                detailedList: this.data.detailedList
            })
        })
    },


    onPullDownRefresh() {
        wx.showNavigationBarLoading()
        this.data.pageNum = 1
        setTimeout(() => {
            wx.hideNavigationBarLoading()
            this.loadList()
            wx.stopPullDownRefresh()
        }, 1000);
    },

    onReachBottom() {
        this.data.pageNum += 1
        this.loadList()
    },

})
